/**
 * 
 */
package com.common;

import java.util.ArrayList;
import java.util.List;

import com.base.Operation;
import com.base.OperationObject;
import com.base.Right;
import com.base.User;
import com.base.enumeration.NeedCheckRightEnum;
import com.common.enumeration.BaseOperationEnum;

/**
 * @author 7738
 *
 */
public class CommonUser<T> extends User {
	/**
	 * common add operation
	 * @param operationObject
	 * @return
	 */
	protected boolean add(OperationObject operationObject) {
		// TODO Auto-generated method stub
		Operation operation = new CommonOperation();
		operation.setCode(BaseOperationEnum.ADD.name());
		return (Boolean) super.doOperation(operation, operationObject);
	}

	/**
	 * common remove operation
	 * @param operationObject
	 * @return
	 */
	protected boolean remove(OperationObject operationObject) {
		// TODO Auto-generated method stub
		Operation operation = new CommonOperation();
		operation.setCode(BaseOperationEnum.DELETE.name());
		return (Boolean) super.doOperation(operation, operationObject);
	}

	/**
	 * common modify operation
	 * @param operationObject
	 * @return
	 */
	protected boolean modify(OperationObject operationObject) {
		// TODO Auto-generated method stub
		Operation operation = new CommonOperation();
		operation.setCode(BaseOperationEnum.MODIFY.name());
		return (Boolean) super.doOperation(operation, operationObject);
	}

	/**
	 * common retrieve operation
	 * @param operationObject
	 * @return
	 */
	protected List<T> retrieve(Operation operation, OperationObject operationObject) {
		// TODO Auto-generated method stub
		return (List<T>) super.doOperation(operation, operationObject);
	}

	/**
	 * common access operation
	 * @param operationObject
	 * @return
	 */
	protected boolean access(OperationObject operationObject) {
		// TODO Auto-generated method stub
		Operation operation = new CommonOperation();
		operation.setCode(BaseOperationEnum.ACCESS.name());
		return (Boolean) super.doOperation(operation, operationObject);
	}

	protected boolean checkRight(Operation operation,
			OperationObject operationObject) {
		if (null == operationObject) {
			System.out.println("no operation object, check right fail !");
			return false;
		}
		
		// TODO Auto-generated method stub
		if (operationObject instanceof TreeNodeOperationObject) {
			// check parent node right
			
		}
		
		if (NeedCheckRightEnum.NO == operationObject.getNeedCheckRightEnum()) {
			
		}
		System.out.println("exec checkRight....");
		return true;
	}

	@Override
	protected List<Right> grantRight(Operation operation,
			OperationObject operationObject) {
		// TODO Auto-generated method stub
		
		// find in database what collection of data can be operate by this operation
		
		return new ArrayList<Right>();
	}
	
}
